package com.example.mykotlin.base.util

class SqlFormat {
    companion object {
        fun format(sql: String?): String? {
            if (sql == null)
                return null
            if (sql.isEmpty())
                return sql
            val sb = StringBuilder()
            sql.forEach {
                sb.append(
                    when (it) {
                        '\\' -> "\\" + it
                        '%' -> "\\" + it
                        '_' -> "\\" + it
                        '\'' -> "\\" + it
                        else -> it
                    }
                )
            }
            return sb.toString()
        }
    }
}